public class Print {
    public static int a = 0;
    public static Object lock = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                synchronized (lock) {
                    if (a <= 200) {
                        System.out.println(a++);
                    }
                }
            }
        });

        Thread t2 = new Thread(() -> {
            while (true) {
                synchronized (lock) {
                    if (a <= 200) {
                        System.out.println(a++);
                    }
                }
            }
        });
        t1.start();
        t2.start();
    }
}
